1 /****************************** Module Header ******************************\
2 * Module Name: CppWin7Direct2D.cpp
3 * Project: CppWin7Direct2D
4 * Copyright (c) Microsoft Corporation.
6 * Defines the entry point for the application.
8 * This source is subject to the Microsoft Public License.
9 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
10 * All other rights reserved.
13 * * 10/11/2009 14:54 Yilun Luo Created
14 \***************************************************************************/
17 #include "CppWin7Direct2D.h"
20 #define MAX_LOADSTRING 100
23 HINSTANCE hInst
; // current instance
24 TCHAR szTitle
[MAX_LOADSTRING
]; // The title bar text
25 TCHAR szWindowClass
[MAX_LOADSTRING
]; // the main window class name
27 // Forward declarations of functions included in this code module:
28 ATOM
MyRegisterClass(HINSTANCE hInstance
);
29 BOOL
InitInstance(HINSTANCE
, int);
30 LRESULT CALLBACK
WndProc(HWND
, UINT
, WPARAM
, LPARAM
);
31 INT_PTR CALLBACK
About(HWND
, UINT
, WPARAM
, LPARAM
);
33 //The Renderer object.
36 int APIENTRY
_tWinMain(HINSTANCE hInstance
,
37 HINSTANCE hPrevInstance
,
41 UNREFERENCED_PARAMETER(hPrevInstance
);
42 UNREFERENCED_PARAMETER(lpCmdLine
);
44 // TODO: Place code here.
48 // Initialize global strings
49 LoadString(hInstance
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
50 LoadString(hInstance
, IDC_CPPWIN7DIRECT2D
, szWindowClass
, MAX_LOADSTRING
);
51 MyRegisterClass(hInstance
);
53 // Perform application initialization:
54 if (!InitInstance (hInstance
, nCmdShow
))
59 hAccelTable
= LoadAccelerators(hInstance
, MAKEINTRESOURCE(IDC_CPPWIN7DIRECT2D
));
62 while (GetMessage(&msg
, NULL
, 0, 0))
64 if (!TranslateAccelerator(msg
.hwnd
, hAccelTable
, &msg
))
66 TranslateMessage(&msg
);
67 DispatchMessage(&msg
);
71 return (int) msg
.wParam
;
77 // FUNCTION: MyRegisterClass()
79 // PURPOSE: Registers the window class.
83 // This function and its usage are only necessary if you want this code
84 // to be compatible with Win32 systems prior to the 'RegisterClassEx'
85 // function that was added to Windows 95. It is important to call this function
86 // so that the application will get 'well formed' small icons associated
89 ATOM
MyRegisterClass(HINSTANCE hInstance
)
93 wcex
.cbSize
= sizeof(WNDCLASSEX
);
95 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
96 wcex
.lpfnWndProc
= WndProc
;
99 wcex
.hInstance
= hInstance
;
100 wcex
.hIcon
= LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_CPPWIN7DIRECT2D
));
101 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
102 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
103 wcex
.lpszMenuName
= NULL
;
104 wcex
.lpszClassName
= szWindowClass
;
105 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, MAKEINTRESOURCE(IDI_SMALL
));
107 return RegisterClassEx(&wcex
);
111 // FUNCTION: InitInstance(HINSTANCE, int)
113 // PURPOSE: Saves instance handle and creates main window
117 // In this function, we save the instance handle in a global variable and
118 // create and display the main program window.
120 BOOL
InitInstance(HINSTANCE hInstance
, int nCmdShow
)
124 hInst
= hInstance
; // Store instance handle in our global variable
126 hWnd
= CreateWindow(szWindowClass
, szTitle
,
127 WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
,
128 CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0, NULL
, NULL
, hInstance
, NULL
);
135 //Create the Renderer object.
136 pRenderer
= new Renderer(hWnd
, 800, 600);
138 ShowWindow(hWnd
, nCmdShow
);
145 // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
147 // PURPOSE: Processes messages for the main window.
149 // WM_COMMAND - process the application menu
150 // WM_PAINT - Paint the main window
151 // WM_DESTROY - post a quit message and return
154 LRESULT CALLBACK
WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
163 case WM_DISPLAYCHANGE
:
164 hdc
= BeginPaint(hWnd
, &ps
);
165 // TODO: Add any drawing code here...
168 break; case WM_DESTROY
:
172 if(!pRenderer
->m_animate
)
174 pRenderer
->m_animate
= true;
175 pRenderer
->m_clickedPointX
= LOWORD(lParam
);
176 pRenderer
->m_clickedPointY
= HIWORD(lParam
);
177 InvalidateRect(pRenderer
->m_hwnd
, NULL
, FALSE
);
181 return DefWindowProc(hWnd
, message
, wParam
, lParam
);